home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / host / Host_ByName.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-30  |  1.9 KB  |  74 lines

  1. /* 
  2.  * Host_ByName.c --
  3.  *
  4.  *    Source code for the Host_ByName library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: Host_ByName.c,v 1.1 88/06/30 11:06:43 ouster Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <stdio.h>
  21. #include <host.h>
  22. #include <hostInt.h>
  23. #include <string.h>
  24.  
  25.  
  26. /*
  27.  *-----------------------------------------------------------------------
  28.  *
  29.  * Host_ByName --
  30.  *
  31.  *    Return information about a host based on its name. The name may
  32.  *    be either the official name of a host or an alias for it.
  33.  *
  34.  * Results:
  35.  *    A Host_Entry pointer describing the host, or NULL if no such host
  36.  *    exists in the current database.  The Host_Entry is statically
  37.  *    allocated, and may be modified on the next call to any Host_
  38.  *    procedure.
  39.  *
  40.  * Side Effects:
  41.  *    The host file is opened if it wasn't already.
  42.  *
  43.  *-----------------------------------------------------------------------
  44.  */
  45.  
  46. Host_Entry *
  47. Host_ByName(name)
  48.     register char     *name;      /* Name of host to find */
  49. {
  50.     register Host_Entry    *entry;        /* Current entry */
  51.     register char     **cpp;        /* Pointer to alias table */
  52.  
  53.     if (Host_Start() != 0) {
  54.     return ((Host_Entry *)NULL);
  55.     }
  56.     
  57.     while (1) {
  58.     entry = Host_Next();
  59.     if (entry != (Host_Entry *)NULL) {
  60.         if (strcmp(entry->name, name) == 0) {
  61.         return (entry);
  62.         } else {
  63.         for (cpp = entry->aliases; *cpp != (char *)NULL; cpp++) {
  64.             if (strcmp(*cpp, name) == 0) {
  65.             return (entry);
  66.             }
  67.         }
  68.         }
  69.     } else {
  70.         return (Host_Entry *) NULL;
  71.     }
  72.     }
  73. }
  74.